package com.android.firstgame;

import android.app.Activity;
import android.graphics.Color;
import android.content.Intent;
import android.view.WindowManager;
import android.app.AlertDialog;
import android.content.pm.ActivityInfo;
import android.content.DialogInterface;
// import android.content.res.Configuration;
import android.view.Window;
import android.os.Bundle;

public class FirstGameActivity extends Activity
{
    /** Called when the activity is first created. */
	DrawView drawView;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);		
    }
	@Override
	public void onStart(){
		super.onStart();
		//ngoai ra con co the add 
		//android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
		//vao AndroidManifest.xml de set full screen		
		//set window full screen code, need import Window and WindowManager
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// end code set window full screen code
		// if(getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
			// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//danh.ngothanh: set game screen to landscape
		drawView = new DrawView(this);		
		setContentView(drawView);
		// setContentView(R.layout.main);
	}
	// @Override
	// public void onConfigurationChanged(final Configuration newConfig)
	// {
		// Ignore orientation change to keep activity from restarting
		// super.onConfigurationChanged(newConfig);
	// }
	@Override
	public void onBackPressed(){
		if(drawView.getCurrentScreen() < 2){
			FirstGameActivity.this.finish();
		}else{
			new AlertDialog.Builder(this)
			   .setMessage("Are you sure you want to exit game ?")
			   .setCancelable(false)
			   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				   public void onClick(DialogInterface dialog, int id) {
						FirstGameActivity.this.finish();
				   }
			   })
			   .setNegativeButton("No", null)
			   .show();
		}
	}
	@Override
	public void onStop(){
		super.onStop();
		//danh.ngothanh: override to stop app when press home
		// drawView.finallize();
		drawView = null;
		FirstGameActivity.this.finish();
	}
}
